package com.imooc.service;

//import com.imooc.dao.mapper.UserMapper;


import com.imooc.dao.repository.UserRepository;
import com.imooc.entity.User;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserService {

    @Autowired
    private UserRepository userRepository;


    public User addOne(User user) {
        return userRepository.save(user);
    }

    public User findById(Long userId) {

        if(userRepository.findById(userId).isPresent())
        return userRepository.findById(userId).get();
        else
            return null;
    }

    public List<User> findUsers(){
        return userRepository.getUser();
    }

}
